package com.peng.config;

import org.aopalliance.intercept.Interceptor;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class InterceptorDemo implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("=======");
        if (request.getSession().getAttribute("id")!=null){
            return true;
        }
        if (request.getRequestURI().contains("login"))
            return true;
        response.sendRedirect(request.getContextPath()+"/WEB-INF/jsp/login.jsp");
        return false;
    }
}
